<template>
  <div class="pad_10">
    <el-form ref="queryRef" :inline="true" label-width="68px">
        <el-form-item>
          <el-button @click="handleQuery">保存</el-button>
          <el-button @click="Cancel">取消</el-button>
        </el-form-item>
    </el-form>
    <el-divider />
    <SetUserSelect
      :key="keys"
      ref="setUserSelect"
      class="queryForm"
      :labelwidth="100"
      :isShowUserBtn="false"
      :buttonIsShow="false"
      :formData="bill"
      :queryParams="datas"
    ></SetUserSelect>
  </div>
</template>
<script setup lang="ts" name="NewDepartment">
import { departmentbyId, ecthDepartment, department as setDate } from "@/api/basicManagement/departmentMana";
 import { watch, getCurrentInstance, ref } from "vue";
 import { useRoute, useRouter } from "vue-router";
import data from './data'
 const { bill, datas } = data
 datas.value = {
  status: '1'
 }
const route:any = useRoute();
const { proxy } = getCurrentInstance();
let proxys: any = proxy;
const { basi_department_status } = proxys.useDict("basi_department_status");
const keys = ref(0)
watch(
  basi_department_status,
  (newV, oldV) => {
    bill.value[2].selectData = basi_department_status
    keys.value = new Date().getTime();
  }
);
  const handleQuery = function():void {
    // setDate
    proxys.$refs.setUserSelect.submitForm().then((val) => {
      (!route.query.id? setDate : ecthDepartment)(val).then(() => {
        proxys.$modal.msgSuccess(`${route.query.id? '修改' : '新增'}成功`);
        const obj = { path: "/basicInformation/departmentMana" };
        proxys.$tab.closeOpenPage(obj);
        datas.value = {}
      })
    })
  }
  const Cancel = () => {
    const obj = { path: "/basicInformation/departmentMana" };
    proxys.$tab.closeOpenPage(obj);
    datas.value = {}
  }
  const changeFun = function(e:any):void {
    console.log(e)
  }

  route.query.id && departmentbyId(route.query.id).then((res) => {
    datas.value = res.data
  })
  
</script>
<style scoped>
.pad_10 {
  padding: 10px;
}
.pad_10  .el-form--inline .el-form-item {
  margin: 0;
}
.el-divider--horizontal {
  margin: 10px 0;
}
</style>